package cn.workreport.util;

import cn.workreport.modules.users.entity.UserEntity;

public class UserChacheFromToken {

    public static final String USER_CACHE_KEY = "login_user_cache";

    /**
     *  获取用户信息
     * @return
     */
    public static UserEntity getUser() {
        return ThreadLocalUtil.get(USER_CACHE_KEY);
    }

    /**
     *  更新用户信息
     * @return
     */
    public static void setUser(UserEntity userEntity) {
        ThreadLocalUtil.set(USER_CACHE_KEY, userEntity);
    }

    /**
     *  删除用户信息
     * @return
     */
    public static void removeUser() {
        ThreadLocalUtil.remove(USER_CACHE_KEY);
    }

    /**
     *  获取用户名
     * @return
     */
    public static String getUserName(){
        UserEntity userEntity = ThreadLocalUtil.get(USER_CACHE_KEY);
        if (userEntity != null){
            return userEntity.getUsername();
        }
        return null;
    }

    /**
     *  获取用户名id
     * @return
     */
    public static Integer getUserId(){
        UserEntity userEntity = ThreadLocalUtil.get(USER_CACHE_KEY);
        if (userEntity != null){
            return userEntity.getId();
        }
        return null;
    }

    /**
     *  获取用户名token
     * @return
     */
    public static String getUserToken(){
        UserEntity userEntity = ThreadLocalUtil.get(USER_CACHE_KEY);
        if (userEntity != null){
            return userEntity.getToken();
        }
        return null;
    }


}
